{% extends 'cms/base.html' %}

{% block title %}
    文章分类
{% endblock %}

{% block head %}
    <script src="{% static 'js/news_category.js' %}"></script>
{% endblock %}

{% block content-header %}
    <h1>文章分类</h1>
{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-12">
        <div class="box box-primary">
            <div class="box-header">
                <button id="add-btn" class="btn btn-primary pull-right" >添加分类</button>
            </div>
            <div class="box-body">
                <table class="table table-bordered">
                    <thead>
                        <tr>
                            <th>分类名称</th>
                            <th>文章数量</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                    {# 获取新闻分类页的内容：分类，分类数量，编辑删除等 #}
                    {# 方法1： #}
                        {% for key ,value in category_nums.items %} {# 在html中获取字典的键值是难点，.items是返回字典的各个项#}
                            <tr data-pk="{{ key.pk }} " data-name="{{ key.name }}">
                                <td>{{ key.name }}</td>
                                <td>{{ value }}</td>
                                <td>
                                    <button class="btn btn-warning btn-xs edit-btn">编辑</button>
                                    <button class="btn btn-danger btn-xs delete-btn">删除</button>
                                </td>
                            </tr>
                        {% endfor %}

                    {# 方法2： #}
{#                        {% for category in categories %}#}
{#                            <tr data-pk="{{ category.pk }} " data-name="{{ category.name }}">#}
{#                                <td>{{ category.name }}</td>#}
                                  {# 从后端获取的字典{ 'cat':'nums' }中获取所有的key与 #}
                                 {# 此时的category作比较，相等就将获取value值，即nums(该分类所的新闻数目) #}
{#                                {% for key ,value in category_nums.items %} {# 在html中获取字典的键值是难点，.items是返回字典的各个项#}
{#                                    {% if key == category %}#}
{#                                        <td>{{ value }}</td>#}
{#                                   {% endif %}#}
{#                                {% endfor %}#}
{#                                <td>#}
{#                                    <button class="btn btn-warning btn-xs edit-btn">编辑</button>#}
{#                                    <button class="btn btn-danger btn-xs delete-btn">删除</button>#}
{#                                </td>#}
{#                            </tr>#}
{#                        {% endfor %}#}
                        
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}